package com.poetize.plus.entity.dto;

import com.poetize.plus.entity.po.Comment;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

/**
 * @author zuosy
 * @created 2024/4/11 16:25
 */
public record CommentDTO(
        @Schema(description = "文章ID")
        @NotNull(message = "文章ID不能为空")
        Long articleId,

        @Schema(description = "评论父ID")
        @NotNull(message = "评论父ID不能为空")
        Long parentId,

        @Schema(description = "评论内容")
        @NotBlank(message = "评论内容不能为空")
        String commentContent
) {

    /**
     * DTO转实体类
     *
     * @param commentDTO
     * @return
     */
    public static Comment convertDTO(CommentDTO commentDTO, Integer floorNum) {
        return new Comment(null, commentDTO.parentId, commentDTO.articleId, floorNum, commentDTO.commentContent);
    }
}
